(function(){if(BX.MaskedInput)return;var t={cypher:{"char":"9",rule:"[0-9]"},hexrgb:{"char":"h",rule:"[A-Fa-f0-9]"},lang_en:{"char":"a",rule:"[a-zA-Z]"}};BX.MaskedInput=function(t){this.mask=t.mask||"";this.placeholder=(t.placeholder||"_").substring(0,1);this.definitions=this.prepareDefinitions(t.definitions||["cypher","lang_en"]);this.stopChangeEvent=false;this.initInput(t)};BX.MaskedInput.prototype.initInput=function(t){if(t.input.tagName=="INPUT"){this.input=new BX.MaskedInputElement({node:t.input})}else{this.input=new BX.MaskedTextElement({node:t.input})}this.dataInput=t.dataInput||null;this.isDataInputClean=t.isDataInputClean||false;this.isHoldOverInputValueInit=t.isHoldOverInputValueInit||false;this.enableCheckingValue=t.enableCheckingValue||false;this.onDataInputChange=t.onDataInputChange||null;this.onDataInputInitValue=t.onDataInputInitValue||null;BX.addCustomEvent(this.input,"change",BX.proxy(this.onInputChange,this));BX.addCustomEvent(this.input,"paste",BX.proxy(this.onInputPaste,this));BX.addCustomEvent(this.input,"delete",BX.proxy(this.onInputDelete,this));BX.bind(this.input.node,"focus",BX.proxy(function(){if(this.getFirstEmptyPosition()===null){return}setTimeout(BX.proxy(function(){this.moveCaret(this.getFirstEmptyPosition())},this),50)},this));if(!this.isHoldOverInputValueInit&&!this.test(this.input.val())){this.input.val(this.getMaskedPlaceholder())}if(this.dataInput){var e=this.dataInput.value;if(BX.type.isFunction(this.onDataInputInitValue)){e=this.onDataInputInitValue.apply(this,[e])}if(BX.type.isString(e)&&e.length>0){this.setValue(e)}BX.addCustomEvent(this,"change",BX.proxy(function(){var t="";if(BX.type.isFunction(this.onDataInputChange)){t=this.onDataInputChange.apply(this,[this.getValueClean(),this.getValue()])}else if(this.isDataInputClean){t=this.getValueClean()}else{t=this.getValue()}if(!BX.type.isString(t)){t=""}if(this.enableCheckingValue&&!this.checkValue()){t=""}this.dataInput.value=t},this))}};BX.MaskedInput.prototype.setMask=function(t){if(this.mask==t){return}var e=this.getValueClean();this.mask=t;this.setChangeEventFiring(false);this.setValue(e);this.setChangeEventFiring(true)};BX.MaskedInput.prototype.getMask=function(){return this.mask};BX.MaskedInput.prototype.setValue=function(t){if(!this.mask){this.input.val(t);this.fireChangeEvent();return}var e=this.input.getSelectionStart();this.moveCaret(0);this.input.val(this.mask);var n=0;for(var i=0;i<this.mask.length;i++){if(!this.isMaskCharReplaceable(i)){this.replaceChar(i,this.mask.charAt(i));continue}while(true){var s=t.charAt(n);if(!s){s=this.placeholder;break}if(s==this.placeholder){break}if(this.testChar(i,s)){break}n++}this.replaceChar(i,s);n++}this.moveCaret(e);this.fireChangeEvent()};BX.MaskedInput.prototype.getValue=function(){return this.input.val()};BX.MaskedInput.prototype.getFirstEmptyPosition=function(){var t=this.getValue();for(var e=0;e<t.length;e++){if(!this.isMaskCharReplaceable(e)){continue}var n=t.charAt(e);if(n==this.placeholder){return e}}return null};BX.MaskedInput.prototype.getValueClean=function(){var t="";var e=this.getValue();if(!this.mask){return e}for(var n=0;n<e.length;n++){if(!this.isMaskCharReplaceable(n)){continue}var i=e.charAt(n);t+=i==this.placeholder?"":i}return t};BX.MaskedInput.prototype.checkValue=function(){var t=this.getValue();if(!this.mask){return t}for(var e=0;e<t.length;e++){if(!this.isMaskCharReplaceable(e)){continue}if(t.charAt(e)==this.placeholder){return false}}return true};BX.MaskedInput.prototype.onInputDelete=function(t){if(this.deleteSelection()){this.fireChangeEvent();return}var e=this.input.getSelectionStart();if(t){if(e===this.mask.length){this.replaceChar(e-1,this.placeholder)}else{this.shift(e,e-1)}this.moveCaret(e-1)}else{if(e===this.mask.length-1){this.replaceChar(e,this.placeholder)}else if(e<this.mask.length-1){this.shift(e+1,e)}this.moveCaret(e)}this.fireChangeEvent()};BX.MaskedInput.prototype.onInputPaste=function(t){this.deleteSelection();for(var e=0;e<t.length;e++){this.setCharOnCaret(t.charAt(e))}this.fireChangeEvent()};BX.MaskedInput.prototype.onInputChange=function(t){if(this.input.val()==""&&this.mask){this.input.val(this.getMaskedPlaceholder());this.input.setCaretPosition(0)}this.deleteSelection();this.setCharOnCaret(t);this.fireChangeEvent()};BX.MaskedInput.prototype.moveCaret=function(t){if(t>this.mask.length){t=this.mask.length}else if(t<0){t=0}else if(t===null){return this.input.getSelectionStart()}this.input.setCaretPosition(t);return t};BX.MaskedInput.prototype.findClosestAllowPosition=function(t,e,n){if(typeof t==="undefined"){t=0}if(typeof e==="undefined"){e=null}if(typeof n==="undefined"){n=false}while(true){if(!n&&t>=this.mask.length){return null}else if(n&&t<=0){return 0}if(this.isMaskCharReplaceable(t)){break}if(!n){t++}else{t--}}if(!this.isMaskCharReplaceable(t)){return null}if(e&&!this.testChar(t,e)){return null}return t};BX.MaskedInput.prototype.setCharOnCaret=function(t){var e=this.input.getSelectionStart();e=this.findClosestAllowPosition(e,t);if(e===null){return}this.shift(e,e+1);e=this.replaceChar(e,t);if(e===null){return}e=this.findClosestAllowPosition(e+1);this.moveCaret(e);if(BX.browser.IsAndroid()&&BX.browser.DetectAndroidVersion()<7){var n=this;setTimeout(function(){n.moveCaret(e)},50)}};BX.MaskedInput.prototype.shift=function(t,e){var n,i=null;var s=[];for(n=t;n<this.mask.length;n++){if(!this.isMaskCharReplaceable(n))continue;var a=this.input.val();s.push(a.charAt(n));this.replaceChar(n,this.placeholder)}s.reverse();for(n=e;n<this.mask.length;n++){if(!this.isMaskCharReplaceable(n))continue;if(s.length>0){i=s.pop()}else{i=this.placeholder}this.replaceChar(n,i)}};BX.MaskedInput.prototype.deleteSelection=function(){var t=this.input.getSelectionStart();var e=this.input.getSelectionEnd();if(t==e){return false}for(var n=t;n<e;n++){if(!this.isMaskCharReplaceable(n)){continue}this.replaceChar(n,this.placeholder)}this.shift(e,t);this.moveCaret(t);return true};BX.MaskedInput.prototype.setChangeEventFiring=function(t){this.stopChangeEvent=!t};BX.MaskedInput.prototype.fireChangeEvent=function(){if(!this.stopChangeEvent){BX.onCustomEvent(this,"change",[this.getValueClean(),this.getValue()])}};BX.MaskedInput.prototype.replaceChar=function(t,e){if(isNaN(t)){return null}var n=this.input.val();var i=n.substring(0,t)+e;i+=t>=n.length?"":n.substring(t+1);n=i;this.input.val(n);return t};BX.MaskedInput.prototype.isMaskCharReplaceable=function(t){var e=this.mask.charAt(t);if(!e){return false}return!!this.definitions[e]};BX.MaskedInput.prototype.getMaskedPlaceholder=function(){var t="";for(var e=0;e<this.mask.length;e++){var n=this.mask[e];if(this.definitions[n]){n=this.placeholder}t+=n}return t};BX.MaskedInput.prototype.prepareDefinitions=function(e){var n={};e.forEach(function(e){if(BX.type.isString(e)&&t[e]){e=t[e]}if(BX.type.isPlainObject(e)){var i={rule:e.rule,isFunction:false};if(BX.type.isFunction(e.rule)){i.isFunction=true}else{i.regexp=new RegExp(e.rule)}n[e.char]=i}},this);return n};BX.MaskedInput.prototype.test=function(t){for(var e=0;e<t.length;e++){var n=this.testChar(e,t[e]);if(!n){return false}}return true};BX.MaskedInput.prototype.testChar=function(t,e){var n=this.mask[t];if(!this.definitions[n]){return e===n}var i=true;if(this.definitions[n].isFunction){i=!!this.definitions[n].func.apply(this,[e])}else{i=this.definitions[n].regexp.test(e)}return i};BX.MaskedInputElement=function(t){this.node=t.node;this.skipTextInputEvent=false;BX.bind(this.node,"paste",BX.proxy(this.onChange,this));BX.bind(this.node,"keypress",BX.proxy(this.onChange,this));if(BX.browser.IsAndroid()&&BX.browser.DetectAndroidVersion()<7){BX.bind(this.node,"textInput",BX.proxy(this.onAndroidInput,this));BX.bind(this.node,"keydown",BX.proxy(this.onAndroidInput,this))}else{BX.bind(this.node,"keydown",BX.proxy(this.onChange,this))}};BX.MaskedInputElement.prototype.val=function(t){if(typeof t!="undefined"){this.node.value=t}return this.node.value};BX.MaskedInputElement.prototype.onAndroidInput=function(t){var e=0;if(t.type=="keydown"){e=typeof t.which=="number"?t.which:t.keyCode;if(e!=8){if(t.key=="Unidentified"){this.skipTextInputEvent=false;BX.PreventDefault(t);return false}else{this.skipTextInputEvent=true}}}else{if(this.skipTextInputEvent){BX.PreventDefault(t);return false}e=t.data.toUpperCase().charCodeAt(0)}var n={keyCode:e,which:e,type:"keydown"};return this.onChange(n,t)};BX.MaskedInputElement.prototype.onChange=function(t,e){var n=true;var i=typeof t.which=="number"?t.which:t.keyCode;if(i<=0){return}switch(t.type){case"keydown":n=!t.ctrlKey&&!t.altKey&&!t.metaKey&&(i&&(i>46&&i<=90||i>145||i===13||i===8||i===46||BX.browser.IsIOS()&&i===127));break;case"keypress":break}if(!n){return}BX.PreventDefault(e||t);if(t.type=="paste"){var s=t.clipboardData||window.clipboardData;var a=s.getData("Text");BX.onCustomEvent(this,"paste",[a])}else if(i===8||i===46||BX.browser.IsIOS()&&i===127){var r=i===8;BX.onCustomEvent(this,"delete",[r])}else{var h=String.fromCharCode(i);BX.onCustomEvent(this,"change",[h])}};BX.MaskedInputElement.prototype.setCaretPosition=function(t){this.node.setSelectionRange(t,t)};BX.MaskedInputElement.prototype.getSelectionStart=function(){if(this.node.selectionStart){return this.node.selectionStart}else if(this.node.createTextRange){var t=this.node.createTextRange().duplicate();t.moveEnd("character",this.node.value.length);if(t.text==""){return this.node.value.length}else{return this.node.value.lastIndexOf(t.text)}}else{return 0}};BX.MaskedInputElement.prototype.getSelectionEnd=function(){if(this.node.selectionEnd){return this.node.selectionEnd}else if(this.node.createTextRange){var t=this.node.createTextRange().duplicate();t.moveStart("character",-this.node.value.length);return t.text.length}else{return 0}};BX.MaskedTextElement=function(t){this.node=t.node};BX.MaskedTextElement.prototype.val=function(t){if(typeof t!="undefined"){this.node.innerText=t}return this.node.innerText};BX.MaskedTextElement.prototype.onChange=function(t){};BX.MaskedTextElement.prototype.setCaretPosition=function(t){};BX.MaskedTextElement.prototype.getSelectionStart=function(){return 0};BX.MaskedTextElement.prototype.getSelectionEnd=function(){return 0}})();
//# sourceMappingURL=masked_input.map.js